package com.tanhua.server.service;

import com.alibaba.fastjson.JSON;
import com.tanhua.domain.mongo.Movement;
import com.tanhua.dubbo.api.mongo.MovementApi;
import com.tanhua.server.interceptors.UserHolder;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class MqMovementService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @DubboReference
    private MovementApi movementApi;

    public void sendMgsToMq(String movementId,int type){
//        Movement movement = movementApi.queryMovementsById(movementId);
        Map map = new HashMap();
        map.put("userId",UserHolder.getUserId());
        map.put("movementId",movementId);
        map.put("type",type);
        String jsonString = JSON.toJSONString(map);
        rabbitTemplate.convertAndSend("movement.score.exchange","movement.score",jsonString);

    }
}
